//
//  Color.swift
//  ss-2t-ios-app
//
//  Created by 胡秋生 on 2019/5/29.
//  Copyright © 2019 胡秋生. All rights reserved.
//
import UIKit
extension UIColor {
    public static func parseColor (_ colorString: String)->UIColor {
    let hexString = colorString.trimmingCharacters(in: .whitespacesAndNewlines)
    let scanner = Scanner(string: hexString)
    
    if hexString.hasPrefix("#") {
        scanner.scanLocation = 1
    }
    
    var color: UInt32 = 0
    scanner.scanHexInt32(&color)
    
    let mask = 0x000000FF
    let r = Int(color >> 16) & mask
    let g = Int(color >> 8) & mask
    let b = Int(color) & mask
    
    let red   = CGFloat(r) / 255.0
    let green = CGFloat(g) / 255.0
    let blue  = CGFloat(b) / 255.0
    
    return UIColor.init(red: red, green: green, blue: blue, alpha: 1)
}
}

